package com.coursehub.progress.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 学生练习完成记录实体类
 */
@Entity
@Table(name = "student_exercise")
@Data
@NoArgsConstructor
@AllArgsConstructor
@IdClass(StudentExerciseId.class)
public class StudentExercise {
    
    /**
     * 学生用户ID
     */
    @Id
    @Column(name = "user_id", nullable = false, length = 100)
    private String userId;
    
    /**
     * 练习ID
     */
    @Id
    @Column(name = "exercise_id", nullable = false, length = 100)
    private String exerciseId;
    
    /**
     * 是否完成练习
     */
    @Column(name = "is_finished", nullable = false)
    private Boolean isFinished = false;
    
    /**
     * 练习得分
     */
    @Column(name = "score")
    private Integer score;
    
    /**
     * 完成时间
     */
    @Column(name = "finished_at")
    private LocalDateTime finishedAt;
    
    /**
     * 创建时间
     */
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
        updatedAt = LocalDateTime.now();
    }
    
    @PreUpdate
    protected void onUpdate() {
        updatedAt = LocalDateTime.now();
    }
}